/*  1:   */ package org.jetbrains.jps.model.serialization.facet;
/*  2:   */ 
/*  3:   */

import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementFactory;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.module.JpsModuleReference;
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;

import java.util.List;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */ 
/* 16:   */ public class JpsFacetSerializer
/* 17:   */ {
/* 18:   */   @NonNls
/* 19:   */   public static final String FACET_TAG = "facet";
/* 20:   */   @NonNls
/* 21:   */   public static final String TYPE_ATTRIBUTE = "type";
/* 22:   */   @NonNls
/* 23:   */   public static final String CONFIGURATION_TAG = "configuration";
/* 24:   */   @NonNls
/* 25:   */   public static final String NAME_ATTRIBUTE = "name";
/* 26:   */   
/* 27:   */   public static void loadFacets(JpsModule paramJpsModule, @Nullable Element paramElement)
/* 28:   */   {
/* 29:42 */     if (paramElement == null) {
/* 30:42 */       return;
/* 31:   */     }
/* 32:43 */     FacetManagerState localFacetManagerState = (FacetManagerState)XmlSerializer.deserialize(paramElement, FacetManagerState.class);
/* 33:44 */     if (localFacetManagerState != null) {
/* 34:45 */       a(paramJpsModule, localFacetManagerState.getFacets(), null);
/* 35:   */     }
/* 36:   */   }
/* 37:   */   
/* 38:   */   public static void saveFacets(JpsModule paramJpsModule, @NotNull Element paramElement)
/* 39:   */   {
/* 40:50 */     if (paramElement == null) {
/* 41:50 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/facet/JpsFacetSerializer", "saveFacets" }));
/* 42:   */     }
/* 43:50 */     FacetManagerState localFacetManagerState = new FacetManagerState();
/* 44:51 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : JpsModelSerializerExtension.getExtensions()) {
/* 45:52 */       for (JpsFacetConfigurationSerializer localJpsFacetConfigurationSerializer : localJpsModelSerializerExtension.getFacetConfigurationSerializers()) {
/* 46:53 */         if (localJpsFacetConfigurationSerializer.hasExtension(paramJpsModule)) {
/* 47:54 */           localJpsFacetConfigurationSerializer.saveExtension(paramJpsModule, localFacetManagerState.getFacets());
/* 48:   */         }
/* 49:   */       }
/* 50:   */     }
/* 51:58 */     XmlSerializer.serializeInto(localFacetManagerState, paramElement, new SkipDefaultValuesSerializationFilters());
/* 52:   */   }
/* 53:   */   
/* 54:   */   private static void a(JpsModule paramJpsModule, List<FacetState> paramList, @Nullable JpsElement paramJpsElement)
/* 55:   */   {
/* 56:62 */     for (FacetState localFacetState : paramList)
/* 57:   */     {
/* 58:63 */       JpsFacetConfigurationSerializer localJpsFacetConfigurationSerializer = a(localFacetState.getFacetType());
/* 59:64 */       if (localJpsFacetConfigurationSerializer != null)
/* 60:   */       {
/* 61:65 */         JpsElement localJpsElement = a(paramJpsModule, localJpsFacetConfigurationSerializer, localFacetState, paramJpsElement);
/* 62:66 */         a(paramJpsModule, localFacetState.getSubFacets(), localJpsElement);
/* 63:   */       }
/* 64:   */     }
/* 65:   */   }
/* 66:   */   
/* 67:   */   private static <E extends JpsElement> E a(JpsModule paramJpsModule, JpsFacetConfigurationSerializer<E> paramJpsFacetConfigurationSerializer, FacetState paramFacetState, JpsElement paramJpsElement)
/* 68:   */   {
/* 69:73 */     return paramJpsFacetConfigurationSerializer.loadExtension(paramFacetState.getConfiguration(), paramFacetState.getName(), paramJpsModule, paramJpsElement);
/* 70:   */   }
/* 71:   */   
/* 72:   */   @Nullable
/* 73:   */   private static JpsFacetConfigurationSerializer<?> a(@NotNull String paramString)
/* 74:   */   {
/* 75:78 */     if (paramString == null) {
/* 76:78 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/facet/JpsFacetSerializer", "getModuleExtensionSerializer" }));
/* 77:   */     }
/* 78:78 */     for (JpsModelSerializerExtension localJpsModelSerializerExtension : JpsModelSerializerExtension.getExtensions()) {
/* 79:79 */       for (JpsFacetConfigurationSerializer localJpsFacetConfigurationSerializer : localJpsModelSerializerExtension.getFacetConfigurationSerializers()) {
/* 80:80 */         if (localJpsFacetConfigurationSerializer.getFacetTypeId().equals(paramString)) {
/* 81:81 */           return localJpsFacetConfigurationSerializer;
/* 82:   */         }
/* 83:   */       }
/* 84:   */     }
/* 85:85 */     return null;
/* 86:   */   }
/* 87:   */   
/* 88:   */   public static JpsModuleReference createModuleReference(String paramString)
/* 89:   */   {
/* 90:89 */     String str = paramString.substring(0, paramString.indexOf('/'));
/* 91:90 */     return JpsElementFactory.getInstance().createModuleReference(str);
/* 92:   */   }
/* 93:   */   
/* 94:   */   public static String getFacetId(JpsModuleReference paramJpsModuleReference, String paramString1, String paramString2)
/* 95:   */   {
/* 96:94 */     return paramJpsModuleReference.getModuleName() + "/" + paramString1 + "/" + paramString2;
/* 97:   */   }
/* 98:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer

 * JD-Core Version:    0.7.0.1

 */